<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">诊所管理</el-breadcrumb-item>
      <el-breadcrumb-item>诊所介绍</el-breadcrumb-item>
    </el-breadcrumb>
    <el-form style="width: 380px;margin-top: 20px;margin-bottom: -10px">
      <el-form-item>
        <el-input size="medium" v-model="editorTitle" placeholder="请输入诊所名称"></el-input>
      </el-form-item>
    </el-form>
    <div id="rich">
    </div>
    <div class="pre-view-box">
      <img src="../../../static/phoneImg.png" alt="" />
      <div class="pre-view" v-html="editorContent"></div>
    </div>
    <div style="margin-top: 20px">
      <el-button size="medium" type="primary" icon="el-icon-view" @click="view">预览</el-button>
      <div style="padding: 5px"></div>
      <el-button size="medium" type="success" icon="el-icon-edit" @click="save">保存</el-button>
    </div>

  </div>
</template>

<script>
import E from 'wangeditor'
import {
  roleList,
  roleSave,
  roleDelete,
  rolePwd,
  RoleRightTree,
  RoleRightSave
} from '../../api/userMG'
import Pagination from '../../components/Pagination'
import {getClinic, updateClinic} from "../../api";
export default {
  data() {
    return {
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editor: {},
      editorContent: '',
      editorTitle: ''
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  watch: {
  },

  /**
   * 创建完毕
   */

  created() {
    this.getData()
  },
  mounted() {
    this.editor = new E('#rich')
    this.editor.config.height = 650
    // 配置 server 接口地址
    this.editor.config.showLinkImg = false
    this.editor.config.uploadFileName = 'file';
    this.editor.config.uploadImgServer = 'https://mp.wwtsz.com:8812/uploadEditor'
    this.editor.config.uploadImgAccept = ['jpg', 'jpeg', 'png', 'gif', 'bmp']
    this.editor.create()
  },

  /**
   * 里面的方法只有被调用才会执行
   */

  methods: {
    getData: function () {
      let _this = this
      getClinic()
      .then(res => {
        _this.editor.txt.html(res.result.introduction)
        _this.editorContent = res.result.introduction
        _this.editorTitle = res.result.name
      })
      .catch(err => {

      })
    },
    view: function () {
      this.editorContent = this.editor.txt.html()
    },
    save: function () {
      let _this = this
      let params = new URLSearchParams()
      params.append('title', _this.editorTitle)
      params.append('content', _this.editor.txt.html())
      updateClinic(params)
      .then(res => {
        console.log(res)
        if(res.result === true) {
          _this.getData()
          _this.$notify({
            title: '成功',
            message: '保存成功',
            type: 'success'
          })
        } else {
          _this.$notify.error({
            title: '错误',
            message: '保存失败'
          })
        }
      })
      .catch(err => {
        _this.$notify.error({
          title: '错误',
          message: '保存失败'
        })
      })
    }
  }
}
</script>

<style scoped>
#rich{
  width: 380px;
  float: left;
}
.pre-view-box{
  position: relative;
  margin-left: 40px;
  margin-right: 40px;
  float: left;
}
.pre-view{
  position: absolute;
  top: 95px;
  left: 26px;
  width: 306px;
  height: 579px;
  padding:  0px 10px;
  background-color: #FFF;
  overflow: auto;
}
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

